package net.wanglu.www.zzz.rule.frag;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.wanglu.www.zzz.rule.BadEgg;

public class SubordinateClauseFragments extends _FragmentsRule {
	
	Pattern subordinateClauseFragments = Pattern
	.compile("^(After|Although|As|Because|Before|Even if|Even though|How|However|If|In order that|Once|Provided that|Since|So|So that|Than|That|Though|Unless|Until|When|Whenever|Where|Whereas|Wherever|Whether|Which|Whichever|While|Who|Whoever|Whom|Whomever|Whose)( \\w+| (\\d+,)+\\d+| \\w+.\\w+)+\\.$");

	@Override
	public Object deviseRightSolution(Object... objects) throws Exception {
		// TODO Auto-generated method stub
		sb.clear();
		sb.append("<p>");
		sb.append("可以把从句残缺句中的从属连词删除, 使之成为一个独立的句子. 例如:");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("误: Because Chase caught the eye of the beautiful brunette in algebra.");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("正: Chase caught the eye of the beautiful brunette in algebra.");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("还可以把从句残缺句放在一个主句后, 构成一个完整的句子, 表达出完整的意思. 例如:");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("误: Until Rachel notices the toilet paper stuck to her shoe.");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("正: We will continue giggling until Rachel notices the toilet paper stuck to her shoe.");
		sb.append("</p>");
		return sb.toString();
	}

	@Override
	public Object examine(Object... objects) throws Exception {
		// TODO Auto-generated method stub
		HashMap<?,?> preprocessData = (HashMap<?, ?>) objects[0];
		String sentence = (String) preprocessData.get("sentence");
		Matcher matcher = subordinateClauseFragments.matcher(sentence);
		if ( matcher.find() ) {				
			BadEgg egg = new BadEgg();
			egg.setViolatedRule(this);
			egg.whereIsWrong = sentence;
			return egg;
		} else {
			return null;
		}			
	}
	
	@Override
	public Object whyItsWrong(Object... objects) throws Exception {
		// TODO Auto-generated method stub
		sb.clear();
		sb.append("<p>");
		sb.append("从句残缺句以从属连词或关系代词或关系副词开头, 这些单词如下:");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("after, although, as, because, before, even if, even though, if, in order that, once, provided that, since, so, so that, than, that, though, unless, until, when, wheneve, where, whereas, whereve, whethe, which, whicheve, while, who, whoeve, whom, whomeve, whose");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("虽然从句残缺句中也含有主语和谓语, 但整个句子仍然无法表达出一个完整的意思. 例如:");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("Because Chase caught the eye of the beautiful brunette in algebra.");
		sb.append("</p>");
		sb.append("<p>");
		sb.append("Until Rachel notices the toilet paper stuck to her shoe.");
		sb.append("</p>");
		return sb.toString();
	}
}
